package com.blazemina.config;

import org.apache.mina.core.filterchain.IoFilter;

import com.blazegame.logging.Logger;
import com.blazegame.logging.LoggerFactory;
import com.blazemina.util.ClassUtils;

/**
 * 
 * @author JackChu
 * @version 1.0.0 2012-2-8 下午2:11:06
 */
public class ServiceFilter extends BaseConfig {
	
	private static final Logger log = LoggerFactory
			.getLogger(ServiceFilter.class);
	
	public static final String TYPE_CODEC_FACTORY = "codecFactory";
	
	private String name;
	private String type;
	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	private String className;
	private IoFilter ioFilter;

	/**
	 * @return the ioFilter
	 */
	public IoFilter getIoFilter() {
		if (ioFilter == null) {
			try {
				ioFilter = (IoFilter) ClassUtils.applicationInstance(className);
			} catch (Exception e) {
				log.error("create ioFilter error, name:"+name+" filterClass:"+className,e);
			} 
		}
		return ioFilter;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		throwIfConfigured();
		this.name = name;
	}

	public String getClassName() {
		return this.className;
	}

	public void setClassName(String className) {
		throwIfConfigured();
		this.className = className;
	}
}